package ch.sv7.tool.dbmanager.db.fix;

import ch.sv7.tool.dbmanager.db.ForeignKeySchema;
import ch.sv7.tool.dbmanager.db.SchemaElement;
import ch.sv7.tool.dbmanager.db.dialect.DialectException;

/**
 * TODO: Document me!
 *
 * @author svt
 *
 */
public class CreateForeignKeyFix extends AbstractSchemaFix implements SchemaFix {

	private ForeignKeySchema fk;

	/**
	 * @param missingTableDifference
	 */
	public CreateForeignKeyFix(ForeignKeySchema fk) {
		super();
		this.fk = fk;
	}

	public SchemaElement getActionTarget() {
		return fk;
	}
	
	public String getSQLFix() throws DialectException {
		String ddl = "\n-- Create Foreign Key Fix \n";
		ddl += getDialect().getAddForeignKeyDDL(fk);
		return ddl;
	}

	public int getPriority() {
		return SchemaFix.PRIORITY_FOREIGN_KEY_CREATION;
	}

	public String getDescription() {
		return "Add foreign key " + fk.getTableSchema().getName() +"."+fk.getName();
	}

	public int getAction() {
		return ACTION_CREATE;
	}



}
